<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<title>Allegro Stuff</title>
	<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<!-- menu -->
	<div id="navmain">
	<ul>
		<li><a href="index.html">Overview</a></li>
		<li><a href="install.html">Installation</a></li>
		<li><a href="config.html">Configurator</a></li>
		<li><a href="animation.html">Animation</a></li>
		<li><a href="framework.html">Framework</a></li>
		<li><a href="tranzam.html">Tutorial</a></li>
	</ul>
	</div>
	<div id="navsub">
	<ul>
		<li><a href="#xml">XML File</a></li>
		<li><a href="#elements">Elements/Attributes</a></li>
		<li><a href="#methods">Methods/Data</a></li>
		<li><a href="#playback">Usage</a></li>
		<li><a href="#tutorial">Examples</a></li>
		<li><a href="#internals">Internals</a></li>
	</ul><span class="smallprint">This menu will stay fixed with a proper browser.</span>
	<p>
	 <a href="http://jigsaw.w3.org/css-validator/">
	  <img style="border:0;width:88px;height:31px"
		   src="http://jigsaw.w3.org/css-validator/images/vcss" 
		   alt="Valid CSS!" />
	 </a>
	</p>
	<p>
      <a href="http://validator.w3.org/check?uri=referer"><img
          src="http://www.w3.org/Icons/valid-xhtml10"
          alt="Valid XHTML 1.0!" height="31" width="88" /></a>
    </p>
<p><a href="http://www.bloggerheads.com/bbc/" ><img src="http://www.bloggerheads.com/bbc/bbc.gif" width="90" height="45"  alt="Click here to find out why." /></a></p>
<p><a href="http://retrospec.sgn.net" ><img src="retrospec.gif" width="150" alt="Fine games" /></a></p>
	</div>
<!-- menu -->

	<div id="main">
		<a name="library"></a>
		<h1>Configurator Library</h1>
<h2>Overview</h2>
The library is fully described in the Overview. However, to summarise it is a system to manage your own custom configuration values, 
core allegro values you might use in a game (such as graphcis mode, colour depth, fps, sound options). It is easy to read and write/update 
existing and new values (there is an auto update option so no explicit saving is required). There is also an 'AllegroStart' function 
that takes some of the core allegro values you specify and starts up allegro. It tries all permutations you specify (e.g. colour depth, graphics mode,
fallback graphics mode, windowing options, etc). If 'AllegroStart' is called again it will re-initialise the system. This will allow (for example) the system
to restart after key changes are made in a game configuration menu.
<a name="xml"></a>
<h2>XML File</h2>
<p>The allegro system variables and custom variables are fully described in the XML. Example1 contains code that shows how easy it is to use.</p>
<p>This is the core of a config file:</p>
<p class="code">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;config&gt;
	&lt;system /&gt;
	&lt;graphics /&gt; 
	&lt;window /&gt;
	&lt;sound /&gt;
	&lt;custom /&gt;
	&lt;custom /&gt;
&lt;/config&gt;
</p>
<p>There is one master element 'config' that contains one each of the core allegro elements 'system', 'graphics', 'window', 
'sound' and zero or more 'custom' elements.<br/><br />
There are defaults for all core allegro elements so if none are present (or indeed if the actual element does not exist,
the system will create them on saving. However the element names must at least exist when reading the config file.</p> 
		<a name="elements"></a>
<h2>Elements and Attributes</h2>
<p>Full details appear below for all attributes, however a short and concise version is contained in the sample config.xml file
that is in the tests\config directory. It's probably best to open up the 
config.xml file and map the table below to what you see:</p>

<p><strong>Element: system</strong></p>
<table style="width: 800px">
<tr><th>Attribute</th><th>Default</th><th>Type</th><th>Valid Entries</th><th>Description</th></tr>
<tr>
<td>fps</td>
<td>60</td>
<td>int</td>
<td>1 to 1000</td>
<td>FPS for a game (not used by Configurator class, only Animation and Framework classes). If using Animation system, this and animation share the same value. This overrides animation</td>
</tr>
<tr>
<td>debugon</td>
<td>0</td>
<td>boolean</td>
<td>0,1</td>
<td>Not used by the config or animation but can be used as a check in game on wheter to log stuff, for example</td>
</tr>
<tr>
<td>autowritemain</td>
<td>0</td>
<td>boolean</td>
<td>0,1</td>
<td>On destructing the configuration object, if 1 will write all data for core allegro elements to the config file</td>
</tr>
<tr>
<td>autowritecustom</td>
<td>0</td>
<td>boolean</td>
<td>0,1</td>
<td>On destructing the configuration object, if 1 will write all data for custom elements to the config file</td>
</tr>
<tr>
<td>enablejoystick<br />
enablemouse<br />
enablekeyboard<br />
enablesound<br />
enablemidi
</td>
<td>1</td>
<td>boolean</td>
<td>0,1</td>
<td>These 5 attributes state which option (e.g. init_keyboard()) is to be called on startup. Timer is exlcuded
because it is assumed it will always be enabled. If not, and using the Configuration to start allegro, modify the code.</td>
</tr>
<tr>
<td>matchrefreshrate</td>
<td>0</td>
<td>boolean</td>
<td>0,1</td>
<td>Signify that on Allegro initialisation, a change to the refresh rate should be attempted. This may improve smoothness and avoid doing too much/too little in a FPS loop.</td>
</tr>
</table>
<p><strong>Element: graphics</strong></p>
<table style="width: 800px">
<tr><th>Attribute</th><th>Default</th><th>Type</th><th>Valid Entries</th><th>Description</th></tr>
<tr>
<td>vsync</td>
<td>0</td>
<td>boolean</td>
<td>0,1</td>
<td>Whether vsync is to be enabled if applicable (e.g. if using double buffering). Only used by the Framework class, not the configurator or animation classes.</td>
</tr>
<tr>
<td>graphicsmode</td>
<td>0</td>
<td>int</td>
<td>0 (double)<br />
1 (dirty rectangle)<br />
2 (video paged)<br />
3 (triple)<br />
</td>
<td>Only used by the Framework class. How the system should be used and tried. If the Configurator is used it will try alternates until
successful or it gives up, i.e. if triple fails paged is tried, if paged or dirty fails, double is tried. double fails, the fallback mode and fallback bitmap depth is tried for all permutations until</td>
</tr>
<tr>
<td>depthpreferred</td>
<td>32</td>
<td>int</td>
<td>32,24,16, 15,8</td>
<td>bpp required. failure will result in depthfallback tried</td>
</tr>
<tr>
<td>depthfallback</td>
<td>16</td>
<td>int</td>
<td>32,24,16, 15,8,0</td>
<td>Fallback mode used if the depthpreferred fails. 0 means no fallback mode allowed</td>
</tr>
<tr>
<td>capbmptype</td>
<td>0</td>
<td>boolean</td>
<td>0,1</td>
<td>Signify that if the drawing buffer is not the same as animations/graphics then the animations/graphics should use the same type, e.g. because VRAM->MEMORY blitting can be extremely slow, if the buffer is a memory bitmap but graphics drawn to it are video, performance can be hit. Setting this flag to 0 will indicate that any type specified should be ignored and to use that of the drawing buffer. This is used by the Framework for loading animations and graphics.</td>
</tr>
</table>
<p><strong>Element: window</strong></p>
<table style="width: 800px">
<tr><th>Attribute</th><th>Default</th><th>Type</th><th>Valid Entries</th><th>Description</th></tr>
<tr>
<td>autodetect</td>
<td>any</td>
<td>string</td>
<td>any, fullscreen, windowed</td>
<td>How the window should be created. All these entries use the GFX_AUTODETECT_xxx mode. Any will 
simply use GFX_AUTODETECT. If another mode is required, see the next attribute. The system will try different valid permutations of this and colour depth in the event of a failure.</td>
</tr>
<tr>
<td>specified</td>
<td><em>not set</em></td>
<td>int</td>
<td>OS specific</td>
<td>If this attribute is specified then 'autodetect' is not used and this is called instead. So only 
use this entry if not using autodetect as it will override it. This is an integer that corresponds to the 
modes available (i.e. that the GFX_AUTODETECT_xxx and all OS specific modes are defined as)</td>
</tr>
<tr>
<td>width<br />height</td>
<td>800<br />600</td>
<td>integer</td>
<td>&gt;0</td>
<td>The width/height required</td>
</tr>
</table>
<p><strong>Element: window</strong></p>
<table style="width: 800px">
<tr><th>Attribute</th><th>Default</th><th>Type</th><th>Valid Entries</th><th>Description</th></tr>
<tr>
<td>maxvoicearray</td>
<td>32</td>
<td>integer</td>
<td>1 to 255</td>
<td>The number of voices to allocate to the sound system</td>
</tr>
<tr>
<td>samplevolume</td>
<td>150</td>
<td>int</td>
<td>0 to 255</td>
<td>The starting volume required for sounds/voices</td>
</tr>
<tr>
<td>musicvolume</td>
<td>128</td>
<td>int</td>
<td>0 to 255</td>
<td>The starting volume required for any music</td>
</tr>
</table>
<p><strong>Element: custom</strong></p>
<table style="width: 800px">
<tr><th>Attribute</th><th>Default</th><th>Type</th><th>Description</th></tr>
<tr>
<td>name</td>
<td><em>not set</em></td>
<td>string</td>
<td>The name of the custom variable. This is how you read/write custom variables as the name is the key. Using dodgy characters may error. So stick to 
no spaces or punctuation, etc. Error if not set</td>
</tr>
<tr>
<td>valuestring<br />
valueint<br />
valuefloat<br />
<td>&quot;&quot;<br />
-1<br />
-1.0<br /></td>
<td>string<br />
int<br />float<br /></td>
<td>One and one only of any of these must be there. If none, the an error is raised. If more than one then precedence (randomly selected for no apparent reason) is int, float, string</td>
</tr>
</table>

<br />
<a name="methods"></a><h2>Methods</h2>
<table style="width:800px">
<tr><th>Method/Data</th><th>Details</th></tr>
<tr><td>Configuration(string xmlfile)</td>
<td>Create a Configuration object and read all values from XML. The 'xmlfile' can be the name of a XML file or the actual XML as a string. See usage below. 
</td></tr>
<tr><td>~Configuration()</td><td>When the destructor is called (i.e. destroyed) and any of the autowrite attributes
 are set, will write the values back to the xml file. If not set then will use the filename 'config.xml'</td></tr>
<tr><td>FileName</td><td>Name of the config file being read/written. Only set this if you wish to write to a 
new config file other than the one read or if XML file was not read (using the second constructor). This is simply a std::string (e.g. NewFile="myfile.xml")</td></tr>
<tr><td>GetCustom(string,int)<br />
GetCustom(string,float)<br />
GetCustom(string,string)<br />
</td><td>Retrieve a value read initially from the XML file. First parameter is the name (i.e. the 'name' attribute in the custom element), the
 second is the default if not found. This can be a string, int or a float. Note on some compilers you may have to explicitly 
 suffix the int/float (e.g. float g=GetCustom("gravity",-9.8F).</td></tr>
<tr><td>SetCustom(string,int)<br />
SetCustom(string,float)<br />
SetCustom(string,int)<br /></td><td>This sets a custom variable. If it already exists it will be overwritten, if not a new one is created (and stored to XML if saved). First parameter is the name (refer to GetCustom() ), 
the second is the value to write (refer to GetCustom() )</td></tr>
<tr><td>FlushCustom(string)</td><td>Write all custom variables to the XML file. Parameter is the filename to write to. If omitted will use that which was read. If none was read then the default of 'config.xml' will be used. 
If 'autowritecustom' attribute is set then this will be called automatically for you on destruction of the configuration object.</td></tr>
<tr><td>FlushMain(string)</td><td>Write all core allegro variables to the XML. Parameter and usage as FlushCustom()</td></tr>
<tr><td>AllegroStart()</td>
<td>Using all core allegro attributes specified, will set up Allegro and leave in a graphics mode. Returns 0 if failed and 
not in a graphics mode, 1 for successful but not all primary attributes specified were set 
(e.g. a fallback depth was used), 2 for fully successful. Refer to the Allegro core data below (specifically CapsActualSystem). Note the warning in the section 'Usage' regarding graphics mode changes).<br />The system will try to initialise the system to pause when you switch out of the application. This should work for most systems and nothing else is required, however full-screen mode in Windows will fail. If pause mode fails (e.g. fullscreen Windows) then AMNESIA mode is set. This mode pauses the program but will lose the contents of the screen. In a game loop this won't matter as your code (or the Framework if using it) will redraw immediately. This mode should work on fullscreen Windows. However if that fails then the fallback of BACKAMNESIA is called. This does not pause your program and blanks your screen! hopefully in a game loop this should be fine, though obviously it may do daft things like have a very large timer value if you are using a FPS based timer. If you wish to cater for this mode then you will have to call 'set_display_callback' to pause the game and redraw on resume.

</td></tr>

<tr><td>LogEntry(string,bool, string)</td><td>This is a static (i.e. can be called without creating a Configuration object and from anywhere in code). Simply writes a string (parameter 1) 
to the file (parameter 3). Parameter 2 determines of the file will be wiped first. Defaults are false (do not wipe) and 'config.log'</td></tr>
<tr><td>GlobalErrorString</td><td>static level string. Used for logging your errors if you wish. It is used by the Configuration to log errors at key points so you can test for them, i.e. failure in XML file, no root 'config' element in XML file, no allegro core elements found.</td></tr>
</table>

<h2>Allegro Core Data</h2>
<table style="width:800px">
Whereas the custom values are modified via Get/Set functions, the core allegro values are accessed directly via structures made 
visible by the configuration object, e.g. myConfiguration->CapsGraphics.WindowMode="fullscreen". If the 'structure' column is blank 
it means it is the same as the previous one. bool values are 0 and 1 for false/true. XML attribute is the value in the XML attribute section 
that this value equates to.
<tr><th>Structure</th><th>Element</th><th>Default</th><th>Description</th><th>XML attribute</th></tr>
<tr><td>CapsSystem</td><td>int fps</td><td>60</td><td>frames per second indicator</td><td>fps</td></tr>
<tr><td></td><td>bool DebugEnabled</td><td>0</td><td>Debugging is enabled for tracing faults/logging details</td><td>debugon</td></tr>
<tr><td></td><td>bool UseMouse</td><td>1</td><td>Enable mouse on Allegro initialisation</td><td>enablemouse</td></tr>
<tr><td></td><td>bool UseKeyboard</td><td>1</td><td>Enable keyboard on Allegro initialisation</td><td>enablekeyboard</td></tr>
<tr><td></td><td>bool UseSound</td><td>1</td><td>Enable samples on Allegro initialisation</td><td>enablesound</td></tr>
<tr><td></td><td>bool UseMidi</td><td>1</td><td>Enable MIDI on Allegro initialisation</td><td>enablemidi</td></tr>
<tr><td></td><td>bool AutoWriteMain</td><td>0</td><td>Save all Allegro core attributes (i.e. these) to disk on destruction of the Configuration object</td><td>autowritemain</td></tr>
<tr><td></td><td>bool AutoWriteCustom</td><td>0</td><td>As AutoWriteMain but for all custom created attributes</td><td>autowritecustom</td></tr>
<tr><td>CapsGraphics</td><td>ScrWidth</td><td>800</td><td>Screen width required</td><td>width</td></tr>
<tr><td></td><td>ScrHeight</td><td>600</td><td>Screen height required</td><td>height</td></tr>
<tr><td></td><td>int RenderMode</td><td>0</td><td>How to start graphics (triple buffering, paged, dirty 
rectangle, double - 3,2,1,0</td><td>graphicsmode</td></tr>
<tr><td></td><td>bool VSync</td><td>0</td><td>Use vsync</td><td>vsync</td></tr>
<tr><td></td><td>int Depth</td><td>32</td><td>Colour depth required</td><td>depthpreferred</td></tr>
<tr><td></td><td>int DepthFallback</td><td>16</td><td>Colour depth required if main fails. 0 means no fallback</td><td>depthfallback</td></tr>
<tr><td></td><td>string WindowMode</td><td>any</td><td>How to create the main window. 'fullscreen', 'window','any'. Use WindowFallback 
if auto mode not required</td><td>autodetect</td></tr>
<tr><td></td><td>int WindowFallback</td><td>0</td><td>Graphics mode to set if this value is >0. Overrides WindowMode and equates to the 
numeric values associated with each graphics mode.</td><td>specified</td></tr>
<tr><td>CapsSound</td><td>SampleVolume</td><td>150</td><td>Initial volume for sound effects</td><td>samplevolume</td></tr>
<tr><td></td><td>MusicVolume</td><td>128</td><td>Initial volume for music effects</td><td>musicvolume</td></tr>
<tr><td></td><td>MaxSounds</td><td>32</td><td>Maximum number of voices to allocate for sound effects</td><td>maxvoicearray</td></tr>
</table>
<p><strong>This structure is populated after initialisation and contains the actual settings selected by the system. Use these in your game.</strong>
<table>
<tr><td>CapsActualSystem</td><td>UseSound</td><td></td><td>Whether sound system is ok. Use this in your game to determine whether to play sounds.</td><td></td></tr>
<tr><td></td><td>UseMidi</td><td></td><td>As UseSound but for Midi</td><td></td></tr>
<tr><td></td><td>DepthUsed</td><td></td><td>Actual Colour depth used (either of preferred or fallback)</td><td></td></tr>
<tr><td></td><td>GraphicsRenderMode</td><td></td><td>Actual render mode used (triple, paging, double buffering)</td><td></td></tr>
</table>
<a name="playback"></a>
<h1>Usage</h1>
<a name="init"></a><h2>Initialising and Loading</h2>
In your source code you need to include the main header file and use the AXL namespace:
<p class="code">#include "axl_config.h";
using namespace AXL_Projects;</p>
<p>There is one class, Configuration. All constructors create a set of base values. Normally you will create a configuration by passing 
in the name of an XML file, e.g. </p>
<p class="code">Configuration* myConfiguration;
myConfiguration=new Configuration("config.xml");</p>
<p>If you wish, you can supply XML data instead of a filename.</p>
<p>To query an existing custom value you would use the var=GetCustom(name, default) method. This is overloaded, which simply means 
depending on the type of your return variable and the default value it will return the correct value, e.g.</p> 
<p class="code">int lastlevel=myConfiguration->GetCustom("lastlevel" , 1);
float g=myConfiguration->GetCustom("gravity", -9.8F);
string author=myConfiguration->GetCustom("author", "unknown author");
<br />Note: some compilers may not interpret a float/int properly so you might have to tell it, e.g. -9.8F in the example above. 
</p>
<p>To update and existing custom value or to write a new one (if it doesn't exist), simply use the SetCustom(name, value). 
Again it knows the type, so simply pass in a string, an int or a float, e.g. </p>
<p class="code">myConfiguration->SetCustom("lastlevel" , lastlevel);
myConfiguration->SetCustom("gravity", g);
myConfiguration->SetCustom("author", author); 
myConfiguration->SetCustom("a_brand_new_item", 99);
</p>
<p>Setting the core allegro attributes is done via the pre-defined structs mentioned above, e.g. </p>
<p class="code">myConfiguration->CapsSystem.maxvoices=64;</p>
<ul><li>If you have AutoWriteMain set to true then on destroying the myConfiguration object (e.g. 'delete myConfiguration') all the core allegro values will be written to the XML file automatically</li>
<li>If you have AutoWriteCustom set to true then on destroying the myConfiguration object all the custom values will be written to the XML file automatically</li>
<li>AutoWriteCustom/AutoWriteMain are not linked, so either can be on or off</li>
<li>If the values are to be saved at a specific point in code (whether autowritemain/autowritecustom is true or false), use <span class="code">myConfiguration->FlushMain()</span> or 
<span class="code">myConfiguration->FlushCustom()</span></li>
<li>FlushMain/FlushCustom can be passed in a filename as the only parameter to save the details to a different XML file. If omitted then 
the file passed in via the constructor is used. If none were supplied then the public class variable myConfiguration->ConfigFile is used (see description in the details above)</li>
</ul>
<h2>Graphics Mode Change</h2>
<p>As you can see adding user definable options menus is as simple as setting autowrite to 1, setting a value when an option is selected, calling the AllegroStart() method and then forgetting about it. See the examples for more code.</p>
If you change graphics modes (e.g. set_gfx_mode() ), for example from a menu option to allow the user to change resolution, etc, then you should delete all animations and reload. This can be done by simply calling 'delete anim' where anim is your animation library, and re-initialising it. If you are using the Framework, it will try to do it for you if you call the Framework method RestartSystem(). This is because if video or system bitmaps are being used they will/might become invalid and/or corrupted. Memory bitmaps should be ok though any change to colour depth/conversion may affect them.</p>

<h2>XML as data</h2>
<p>Instead of passing in the name of a XML file to the constructor you can specify XML as a string instead. This is useful if you 
are reading the XML from a source other than a file (e.g. a dat file) or you do not wish the user to modify values. Remember that all attributes 
need to be quoted. The easiest way to do this is to simply copy the XML data from the sample config.xml files. For example:</p>
<p class="code">
std::string config = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
"&lt;config&gt;"
"    &lt;system fps=\"60\" autowritemain=\"0\" autowritecustom=\"0\" "
"		enablejoystick=\"0\" enablekeyboard=\"1\" enablemouse=\"1\" enablesound=\"1\" "
"	/&gt;"
"    &lt;window width=\"640\" height=\"480\" autodetect=\"windowed\" /&gt;"
"    &lt;custom name=\"message\" valuestring=\"Hi Mam\" /&gt;"
"&lt;/config&gt;";
MyConfig=new Configuration(config);</p>

<a name="tutorial"></a>
<h1>Examples</h1>
These are found in the tests\config directory (.\example1 and .\example2). VS2005 and Dev-C++ projects have already been created. If not using either of these two IDe's then follow the installation section, i.e. include tinyXML library file (or tinyXML source files), the main.cpp in the example directory and axl_config.cpp. Additionally, example 2 requires axl_animations.cpp.
<ul><li>The first test (example 1) reads an XML configuration file, initialises Allegro and updates some custom values in the XML file</li>
<li>The second test (example 2) is the same as the Animation example 1. The animation example 1 shows some animation effects. This example modifies the example 1 to use the configuration module to set up and initialise allegro. Read this example after you have read the Animation help and done example 1</li>
</ul>
<a name="internals"></a>
<h1>Internals</h1>
This is not an exhaustive list of what and how the configurator works, for that you need to read the code. This provides a list of what the Constructor/AllegroStart methods do so that you know what happens within allegro.
<ul>
<li>The constructor passing in the config xml file loads up the XMl file and sets all the internal data</li>
<li>The AllegroStart method installs the keyboard, timer, joystick, sound, midi, mouse (only the ones you specify in the XML), sets the colour depth and graphics mode (it will use the fallback colour depth and alternative fullscreen/windowed if unavailable). All the data that can change (e.g. colour depth, graphics mode, etc) are stored in the CapsActualSystem to allow you to easily check whether what you got was what was specified.</li>
</ul>
</div>
</body>
</html>
